<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>文章列表</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="cache-control" content="no-cache"/>
    <meta http-equiv="expires" content="0"/>
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"/>
    <meta http-equiv="description" content="This is my page"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/easyUI/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/publicStyle.css"/><!--分页样式-->
</head>
<body style="overflow: hidden; width: 98%; height: 100%;">
<!-- 工具按钮区 -->
<form class="form-horizontal" action="" method="post" >
    <table class="table-condensed">
        <tbody>
        <tr>
            <td>
                <input name="title" id="title" type="text" class="form-control" placeholder="标题">
            </td>
            <td>
                <button type="button" id="selectArticle" class="btn btn-info  operas" onclick="selArticle(1)"><span class="glyphicon glyphicon-search"></span>&nbsp;查询</button>
                <a id="addArticle" class="btn btn-success operas"><span class="glyphicon glyphicon-plus"></span>&nbsp;添加</a>
            </td>
        </tr>
        </tbody>
    </table>
</form>
<div class="panel panel-primary" style="padding-left: 5px;">
    <div class="panel-heading" style="background-color: #11a9e2;">
        <label>文章列表</label>
    </div>
    <div class="panel-body">
        <table class="table table-bordered table-hover" style="margin-bottom: 0;">
            <thead>
            <tr style="font-size: 12px;" align="center">
                <th width="320" style="text-align: center;">文章标题</th>
                <th style="text-align: center;">作者</th>
                <th width="160" style="text-align: center;">发布时间</th>
                <th style="text-align: center;">文章分类</th>
                <th style="text-align: center;">文章标签</th>
                <th width="270" style="text-align: center;">操作</th>
            </tr>
            </thead>
            <tbody id="data_info">

            </tbody>
        </table>

    </div>
    <!--分页条-->
    <div class="pager" id="pager"></div>
</div>

<div id="divDialog">
    <!-- 放置一个添加用户的界面  -->
    <iframe id="iframe" frameborder="0" style="width: 100%;height: 100%;"></iframe>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/jquery/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/jquery/jquery-migrate-1.2.1.min.js"></script>
<!--分页  -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.myPagination.js"></script>
<!-- 导入bootStrap的库 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/layer/2.4/layer.js"></script>
<script type="text/javascript"src="${pageContext.request.contextPath}/resources/plugins/layer/2.4/LayConstant.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
      selArticle(1);
    });
    var pageSize = 4;
   function selArticle(pageNo){
	   var title = $("#title").val();
        var params={"pageNo":pageNo,"pageSize":pageSize,"title":title};
        var obj = $("#data_info");
        obj.empty();
        $.ajax({
            url:'${pageContext.request.contextPath}/article/seltArticleList.jspx',
            data:params,
            type:'post',
            dataType:'json',
            success:function(data){
                if(data.code==0){
                    var content = data.content[0].info,code="";
                    var pageCount = data.content[0].pagetotal;//总页数
                    if (content.length < 1) {
                        layer.msg("暂无数据", {icon: 5, time: LayUIConstant.TIP_TIME});
                    } else {
                        for (var i = 0; i < content.length; i++) {
                            var articleId = content[i].sysid;
                            var isDisplay = content[i].isDisplay;
                            var isComment = content[i].isComment;
                            code +=  '<tr id="dataTr_'+i+'" align="center">'+
                                    '<td>'+content[i].title+'</td>'+
                                    '<td>'+content[i].author+'</td>'+
                                    '<td>'+content[i].publishDatetime+'</td>'+
                                    '<td>'+content[i].classifyName+'</td>'+
                                    '<td>'+content[i].label+'</td>'+
                                    '<td>'+
                                    '<button type="button" class="btn btn-primary" onclick= "updateArticle(\'' + articleId + '\')">编辑</button> ';
                                    if (isDisplay == 'Y'){
                                        code += '<button type="button" class="btn btn-success" onclick="isShow(\'' + articleId + '\')">显示</button> ';
                                    }else{
                                        code += '<button type="button" class="btn btn-warning" onclick="isShow(\'' + articleId + '\')">隐藏</button> ';
                                    }
                                    if (isComment == 'Y'){
                                        code += '<button type="button" class="btn btn-success" onclick="isComment(\'' + articleId + '\')">允许评论</button> ';
                                    }else{
                                        code += '<button type="button" class="btn btn-danger" onclick="isComment(\'' + articleId + '\')">禁止评论</button> ';
                                    }

                            code += '<button type="button" class="btn btn-danger" onclick="del(\'' + articleId + '\')">删除</button>'+
                                    '</td>'+
                                    '</tr>';
                        }
                        obj.append(code);
                        if (pageCount > 0) {
                            //分页
                            $("#pager").myPagination({
                                currPage: pageNo, //初始选择的页数
                                pageCount: pageCount,//总页数
                                pageSize: pageSize //显示多少页
                            });
                        }
                    }
                }else{
                    layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error:function(data){
                layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }
    function pageOnClick(page) {
        selArticle(page);
    }
    //分页文本框中直接输入时触发： properchange：适用IE9以及以上版本  onchange：IE不适用  两者必须有获取焦点失去焦点后才能触发
    function inputChange() {
        var pageNo = $('#pageInput').val();//文本框中当前页
        selArticle(pageNo);
    }


    //添加文章
    $("#addArticle").click(function () {
        window.open("${pageContext.request.contextPath}/article/showAddArticle.jspx","","width=1300px,height=700px,center=yes, resizable=no,scroll=no,modal=yes,status=no")
    })

    //修改文章
    function updateArticle(articleId) {
        window.open("${pageContext.request.contextPath}/article/updateArticle.jspx?articleId="+articleId,"","width=1300px,height=700px,center=yes, resizable=no,scroll=no,modal=yes,status=no")
    }

    //是否显示
    function isShow(articleId){
        $.ajax({
            url:"${pageContext.request.contextPath}/article/isShow.jspx",
            data:{"articleId":articleId},
            type:'post',
            dataType:'json',
            success:function (data) {
                if (data.code == 0) {
                	layer.msg(data.message, {icon: 1, time: LayUIConstant.TIP_TIME});
                    setTimeout(function () {
                        setTimeout("myrefresh()",1500);
                    }, 1500);
                } else {
                	layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error:function (data) {
            	layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }

    //是否允许评论
    function isComment(articleId){
        $.ajax({
            url:"${pageContext.request.contextPath}/article/isComment.jspx",
            data:{"articleId":articleId},
            type:'post',
            dataType:'json',
            success:function (data) {
                if (data.code == 0) {
                	 layer.msg(data.message, {icon: 1, time: LayUIConstant.TIP_TIME});
                    setTimeout(function () {
                    	myrefresh();
                    }, 1500);
                } else {
                	 layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error:function (data) {
            	 layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }

    //删除文章
    function del(articleId){
    	if(!confirm("是否删除选中的项？")){
            return;
        }
        $.ajax({
            url:'${pageContext.request.contextPath}/article/delArticle.jspx',
            data:{"articleId":articleId},
            type:'post',
            dataType:'json',
            success:function(data){
                if(data.code == 0){
                	 layer.msg(data.message, {icon: 1, time: LayUIConstant.TIP_TIME});
                    setTimeout(function () {
                    	myrefresh();
                    }, 1500);
                }else{
                	 layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error:function (data) {
            	 layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }




    //批量删除
    function delArticle(){
    	var checkedId = dataBoxs.filter(":checked");
    	var idArr = [];
        if(checkedId.length < 1){
            swal("请选择需要删除的项!","","error");
        }else{
            for(var i = 0;i < checkedId.length;i++){
                idArr.push(checkedId.eq(i).val());
            }
            if(!confirm("是否删除选中的项？")){
                return;
            }
            $.ajax({
                url:"${pageContext.request.contextPath}/article/delMoreArticle.jspx",
                data:{"ids":idArr.join(",")},
                type:"post",
                dataType:"json",
                success:function (data) {
                    if(data.code == 0){
                        swal(data.message,"","success");
                        setTimeout("myrefresh()",1500);
                    }else{
                        swal(data.message,"","error");
                    }
                },
                error:function (data) {
                    swal(data.message,"","error");
                }
            });
        }
    }
 function myrefresh(){
        window.location.reload();
 }
</script>


</body>

</html>





































